package com.lovebridge.ui;

import com.jiehoo.ooqi.SearchResult;
import com.lovebridge.model.Base;
import com.lovebridge.model.User;
import com.lovebridge.service.IUserService;
import com.lovebridge.service.ServiceFactory;

/**
 * UserListWindow.
 */
public class UserListWindow extends BaseListWindow
{
    IUserService userService = ServiceFactory.getUserService();

    public UserListWindow()
    {
        addListName(getDefaultListName());
        addSortableProperty("name");
        addSortableProperty("email");
        addSortableProperty("role");
        service = this;
    }

    protected String getDefaultListName()
    {
        return "user";
    }

    protected Base newObject()
    {
        return new User();
    }

    public SearchResult query(String name) throws Exception
    {
        return userService.getUsers(queryInfos.get(name));
    }

    public void delete(Base object) throws Exception
    {
        userService.delete(object);
    }

    public void create(Base object) throws Exception
    {
        userService.create(object);
    }

    public void update(Base object) throws Exception
    {
        userService.update(object);
    }
}
